﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;
using System.Configuration;

namespace olierFrm.OAuth.Models
{
    public class OAuthConfig
    {
        public ConfigEntity Config
        {
            get;
            private set;
        }

        public OAuthConfig(OAuthType type)
        {
            NameValueCollection OAuthSection = null;
            if (type == OAuthType.QQ)
            {
                OAuthSection = (NameValueCollection)ConfigurationManager.GetSection("OAuth/Qzone");
            }
            else if (type == OAuthType.Sina)
            {
                OAuthSection = (NameValueCollection)ConfigurationManager.GetSection("OAuth/Sina");
            }
            Config = new ConfigEntity();
            Config.BaseUrl = OAuthSection["BaseUrl"];
            Config.AppKey = OAuthSection["AppKey"];
            Config.AppSecret = OAuthSection["AppSecret"];
            Config.CallBackURI = OAuthSection["CallBackURI"];
        }

        public enum OAuthType
        {
            QQ = 1,
            Sina = 2
        }

        [Serializable]
        public class ConfigEntity
        {
            /// <summary>
            /// 请求的基本网址
            /// 如:https://api.weibo.com
            /// </summary>
            public string BaseUrl { get; set; }

            /// <summary>
            /// AppKey
            /// </summary>
            public string AppKey { get; set; }

            /// <summary>
            /// AppSecret
            /// </summary>
            public string AppSecret { get; set; }

            /// <summary>
            /// 回调域名
            /// </summary>
            public string CallBackURI { get; set; }
        }
    }
}